Skip to content

Conversation

ChuanqiXu9
Copy link
Member

Close #99825

The root cause of the issue is that I didn't realize the things in implicit global module (the language linkage in module interfaces) should be considered in module purview.

@ChuanqiXu9 ChuanqiXu9 added clang:modules C++20 modules and Clang Header Modules skip-precommit-approval PR for CI feedback, not intended for review labels Aug 9, 2024
@ChuanqiXu9 ChuanqiXu9 self-assigned this Aug 9, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Aug 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 9, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)

Changes

Close #99825

The root cause of the issue is that I didn't realize the things in implicit global module (the language linkage in module interfaces) should be considered in module purview.


Full diff: https://github.com/llvm/llvm-project/pull/102574.diff

2 Files Affected:

  • (modified) clang/lib/AST/Decl.cpp (+7-7)
  • (added) clang/test/Modules/pr99825.cppm (+8)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d832ce4190ff1a..e125143bc1b270 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -583,12 +583,6 @@ static bool isSingleLineLanguageLinkage(const Decl &D) {
   return false;
 }
 
-static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
-  if (auto *M = D->getOwningModule())
-    return M->isInterfaceOrPartition();
-  return false;
-}
-
 static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
   return LinkageInfo::external();
 }
@@ -642,7 +636,13 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
     // (There is no equivalent in C99.)
     if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
         !Var->getType().isVolatileQualified() && !Var->isInline() &&
-        !isDeclaredInModuleInterfaceOrPartition(Var) &&
+        ![Var]() {
+          // Check if it is module purview except private module fragment
+          // and implementation unit.
+          if (auto *M = Var->getOwningModule())
+            return M->isInterfaceOrPartition() || M->isImplicitGlobalModule();
+          return false;
+        }() &&
         !isa<VarTemplateSpecializationDecl>(Var) &&
         !Var->getDescribedVarTemplate()) {
       const VarDecl *PrevVar = Var->getPreviousDecl();
diff --git a/clang/test/Modules/pr99825.cppm b/clang/test/Modules/pr99825.cppm
new file mode 100644
index 00000000000000..fe6541c6e68e50
--- /dev/null
+++ b/clang/test/Modules/pr99825.cppm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
+// expected-no-diagnostics
+export module mod;
+
+extern "C++"
+{
+    export constexpr auto x = 10;
+}

@ChuanqiXu9 ChuanqiXu9 merged commit 8410bab into llvm:main Aug 9, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected internal linkage of const/constexpr variable within extern "C++"
2 participants